
from human.human import Human
from langchain_community.callbacks import get_openai_callback

class Service(Human):
    count = 0
    def __init__(self,id,name):
        Service.count += 1
        super().__init__(id,name,'service')

    def setQAChain(self,qa_chain):
        self.qachain = qa_chain
    
    def info(self):
        return {
            "id":self.id,
            "name":self.name
        }
    
    def chat(self,message):
        result = ''
        with get_openai_callback() as cb:
            result = self.qachain.invoke(({"query": message}))
        return {
            "result": result,
            "cost_token": cb.total_tokens,
            "cost_money": round(cb.total_cost,5)
        }
        